
package com.aispeech.testcustom.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import com.aispeech.testcustom.TiApplication;

public class PreferenceUtil {
    public static final String IS_INIT_SDK_IN_APPLICAION = "init_aios_sdk_in_application";
    public static final String IS_SHOW_SPLASH = "is_show_splash";
    //    public static final String ALREADY_INIT_SDK = "already_init_sdk";
    public static final String SETTINGS_LOG_LIST         = "settings_log_list";
    public static final String SAVE_ORIGINAL_MSWAKE_AUDIO = "save_original_mswake_audio";
    public static final String SAVE_AEC_MSWAKE_AUDIO = "save_aec_mswake_audio";

    public static String getString(Context context, String key, String def) {
        SharedPreferences sp = PreferenceManager
                .getDefaultSharedPreferences(TiApplication.getContext());

        return sp.getString(key, def);
    }

    public static String getString(Context context, String key) {
        return getString(context, key, "");
    }


    public static void setString(Context context, String key, String value) {
        SharedPreferences sp = PreferenceManager
                .getDefaultSharedPreferences(TiApplication.getContext());
        sp.edit().putString(key, value).commit();
    }

    public static boolean getBoolean(Context context, String key, boolean def) {
        SharedPreferences sp = PreferenceManager
                .getDefaultSharedPreferences(TiApplication.getContext());
        return sp.getBoolean(key, def);
    }

    public static boolean getBoolean(Context context, String key) {
        return getBoolean(context, key, false);
    }

    public static void setBoolean(Context context, String key, boolean value) {
        SharedPreferences sp = PreferenceManager
                .getDefaultSharedPreferences(TiApplication.getContext());
        sp.edit().putBoolean(key, value).commit();
    }

    public static int getInteger(Context context, String key, int def) {
        SharedPreferences sp = PreferenceManager
                .getDefaultSharedPreferences(TiApplication.getContext());
        return sp.getInt(key, def);
    }

    public static void setInteger(Context context, String key, int value) {
        SharedPreferences sp = PreferenceManager
                .getDefaultSharedPreferences(TiApplication.getContext());
        sp.edit().putInt(key, value).apply();
    }


    /**
     * 设置界面preference
     */
    public static class SettingPreference {

        public static boolean isShowSPlash(Context context){
            return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(IS_SHOW_SPLASH,true);
        }

        public static boolean isInitInApplication(Context context) {
            return PreferenceManager.getDefaultSharedPreferences(context).getBoolean
                    (IS_INIT_SDK_IN_APPLICAION, true);
        }

    }
}
